/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package general.converters;
import general.util.MyPassDataUtil;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import jpa.controller.PedidoJpaController;
import jpa.entity.Pedido;
/**
 *
 * @author isaias
 */
@FacesConverter(value="pedidoConverter")
public class PedidoConverter implements Converter{
     public Object getAsObject(FacesContext fc, UIComponent uic, String name) {
      
        return new PedidoJpaController().findPedidoForNumber(name, MyPassDataUtil.getInstance().getCurrentObra());
    }

    public String getAsString(FacesContext fc, UIComponent uic, Object o) {

        if(o instanceof Pedido){
            return ((Pedido)o).getNumber();
        }

        return null;
    }
}
